<template>
  <div class="component__news_card" @click="toPath(detail.id)">
    <div class="news-content" :class="isShowBottomLine ? 'show-bottom':''">
      <div class="news-left">
        <div class="news-title">{{detail.title}}</div>
        <div class="news-info">
          <span style="margin-right:.2rem;">{{formatDate(detail.publishTime)}}</span>
          <span>发布者：{{detail.author}}</span>
        </div>
      </div>
      <div class="news-right">
        <img v-if="detail.mainDiagram" :src="detail.mainDiagram" alt />
        <img v-else src="/img/mobile/news_default.png" alt />
      </div>
    </div>
    <!-- <div class="news-content">
      <div class="news-left">
        <div class="news-title">工商管理4月份考试课表已发布到各个班级，请及时 ...1</div>
        <div class="news-info">
          <span style="margin-right:.2rem;">{{formatDate(1607742480299)}}</span>
          <span>发布者：曾老师</span>
        </div>
      </div>
      <div class="news-right">
        <img src="/img/mobile/news_default.png" alt />
      </div>
    </div> -->
  </div>
</template>
<script>
import { mapState } from "vuex";
export default {
  props: ["detail","isShowBottomLine"],
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapState({
      is_ios(state) {
        return state.is_ios;
      },
      is_in_wechat(state) {
        return state.is_in_wechat;
      },
    }),
  },
  watch: {},
  methods: {
    formatDate(timestamp) {
      let date = new Date(timestamp);
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      let hour = date.getHours();
      let minute = date.getMinutes();
      let second = date.getSeconds();
      let add0 = (m) => {
        return m < 10 ? "0" + m : m;
      };
      let showTime = null;
      if (new Date(timestamp).toDateString() === new Date().toDateString()) {
        if (hour < 10) {
          showTime = "上午";
        } else if (hour < 12) {
          showTime = "中午";
        } else if (hour < 18) {
          showTime = "下午";
        } else {
          showTime = "晚上";
        }
        // console.log("今天", showTime + " " + add0(hour) + ":" + add0(minute));
        return showTime + " " + add0(hour) + ":" + add0(minute);
      } else {
        // console.log("以前", add0(year) + "/" + add0(month) + "/" + add0(day));
        return add0(year) + "/" + add0(month) + "/" + add0(day);
      }
    },
    toPath(id) {
      this.$router.push({
        path: "/m/school-information-detail",
        query: {
          id,
        },
      });
    },
  },
  created() {
    console.log(this.detail);
    this.formatDate(1607655671000);
    this.formatDate(1607742480299);
  },
  mounted() {},
};
</script>
<style lang="scss" scoped>
.component__news_card {
  padding: 0 .2rem;
  width: 7.2rem;
  .news-content {
    padding: 0.2rem 0;
    width: 6.8rem;
    display: flex;
    justify-content: space-between;
    height: 2rem;
    position: relative;
    
    .news-left {
      padding: .1rem 0;
      width: 5rem;
      .news-title {
        font-size: 0.288rem;
        line-height: 0.4rem;
        height: 0.8rem;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        overflow: hidden;
        text-overflow: ellipsis;
        -webkit-box-orient: vertical;
        margin-bottom: 0.3rem;
      }
      .news-info {
        font-size: 0.26rem;
        color: #babec2;
      }
    }
    .news-right {
      // width: 30%;
      display: flex;
      align-items: center;
      img {
        width: 1.5rem;
        height: 1.5rem;
        display: block;
        margin: 0 auto;
      }
    }
  }
  .news-content.show-bottom {
    border-bottom: solid 0.02rem #ededf1;
  }
}
</style>
<style lang="scss">
.component__news_card {
}
</style>